package fr.vvins.core.services;

import javax.annotation.Resource;
import javax.ws.rs.Path;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import fr.vvins.core.biz.search.SearchException;
import fr.vvins.core.cms.page.PageException;
import fr.vvins.core.cms.page.PageManager;
import fr.vvins.core.cms.page.dto.PageDto;
import fr.vvins.core.common.TechnicalException;

@Path("/page")
@Component("pageService")
public class PageServiceImpl implements PageService {

	@Resource(name="pageManager")
	private PageManager pageManager;

	@Override
	public PageDto getPage(Integer id) throws TechnicalException, PageException {
		if(id == null){
			throw new PageException(SearchException.EMPTY_PARAMETER,"Le parametre 'id' est vide");
		}
		return pageManager.getPage(id);
	}

	@Override
	public PageDto getPage(String name) throws TechnicalException, PageException {
		if(!StringUtils.hasLength(name)){
			throw new PageException(SearchException.EMPTY_PARAMETER,"Le parametre 'name' est vide");
		}
		return pageManager.getPage(name);
	}
	
	@Override
	public PageDto getPageByContent(String name, String content) throws TechnicalException, PageException {
		if(!StringUtils.hasLength(name)){
			throw new PageException(SearchException.EMPTY_PARAMETER,"Le parametre 'name' est vide");
		}
		if(!StringUtils.hasLength(content)){
			throw new PageException(SearchException.EMPTY_PARAMETER,"Le parametre 'content' est vide");
		}
		return pageManager.getPageByContent(name, content);
	}
}
